package com.hankol.newretail.adapter

import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.baselibrary.extension.checkNotNull
import com.baselibrary.extension.checkValue
import com.baselibrary.extension.load
import com.baselibrary.extension.setMallPriceTTF
import com.baselibrary.utils.AmountUtil
import com.baselibrary.utils.NumberUtils
import com.baselibrary.utils.SpUtils
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.hankol.newretail.R
import com.hankol.newretail.bean.GoodListBean

/*新零售商城-商品分类下的列表 一行二个 */
class MallGoodsListOnelineTwoAdapter : BaseQuickAdapter<GoodListBean, BaseViewHolder>(R.layout.item_mall_good_one_line_two) {

    override fun convert(helper: BaseViewHolder, item: GoodListBean) {
        helper.apply {
            item.let {
                getView<ImageView>(R.id.img_cover).load(mContext, it.icon.checkValue())
                setText(R.id.tv_name, it.name.checkValue())
                val tempPrice = if (it.seckillActProductDTO.checkNotNull()) (if (SpUtils.getInstance().isFans) it.seckillActProductDTO?.fansPrice else it.seckillActProductDTO?.price) else it.showPrice
                setText(R.id.tv_price, "${AmountUtil.changeF2Y("${tempPrice}")}")
                setText(R.id.tv_month_sell, "月销 ${NumberUtils.formatBigNumForSale("${it.virtualPayPersonNum}")}+")
                setGone(R.id.tv_month_sell, it.virtualPayPersonNum != 0)
                getView<TextView>(R.id.tv_price).setMallPriceTTF(mContext)
                //标签
                val rvLabel = getView<RecyclerView>(R.id.rv_label)
                val labelAdapter = GoodsLabelAdapter()
                rvLabel.adapter = labelAdapter
                labelAdapter.setNewData(if (it.mallLabelDtoList.size > 3) it.mallLabelDtoList.subList(0, 3) else it.mallLabelDtoList)
                //是否显示视频标识
                setGone(R.id.img_is_video, it.hasVideos == 1)
                //是否显示秒杀标签
                setGone(R.id.img_seckill_price, it.seckillActProductDTO.checkNotNull())
            }
        }
    }
}